#include "scandialog.h"
#include "ui_scandialog.h"

ScanDialog::ScanDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ScanDialog)
{
    ui->setupUi(this);
}

ScanDialog::~ScanDialog()
{
    delete ui;
}


void ScanDialog::on_pushButton_clicked()
{
    QString directory = \
            QFileDialog::getExistingDirectory(this,tr("选择目录"),\
                                              QDir::currentPath(),QFileDialog::ShowDirsOnly|\
                                              QFileDialog::DontResolveSymlinks);
    if (!directory.isEmpty()) {
        ui->pathEdit->setText(directory);
        this->setUserPath(directory);
    }
}

QString ScanDialog::getUserFormat() const
{
    return userFormat;
}

void ScanDialog::setUserFormat(const QString &value)
{
    userFormat = value;
}

QString ScanDialog::getUserPath() const
{
    return userPath;
}

void ScanDialog::setUserPath(const QString &value)
{
    userPath = value;
}

void ScanDialog::on_buttonBox_accepted()
{
    if(ui->pathEdit->text().isEmpty()){
        this->setUserPath("/");
    }
    if(ui->formatEdit->text().isEmpty()){
        this->setUserFormat("mp3");
    }else{
        QString format = ui->formatEdit->text();
        this->setUserFormat(format);
    }
    QStringList userInfoList;
    userInfoList<<this->getUserPath()<<this->getUserFormat();
    emit startScanInfoReady(userInfoList);
}
